#ifndef _DSWWANMSGSESSION_H
#define _DSWWANMSGSESSION_H

#include "libtcpcombase/dswmessagesession.h"

class CDswWanMsgSession : public CDswmessagesession
{
public:
	CDswWanMsgSession();
	virtual ~CDswWanMsgSession();
public:
	CDswWanMsgSession(LPST_ENV_T pEnv, struct bufferevent * pBev, int nHeadSize, char* pHost, int nPort, EN_MISSION_TYPE nType, CB_ON_MISSION_NOTIFY pFunc, void* pParent);
	static CDswWanMsgSession* createNew(LPST_ENV_T pEnv, char* pHost, int nPort, EN_MISSION_TYPE nType, CB_ON_MISSION_NOTIFY pFunc, void* pParent);
private:
	virtual void OnError(EN_ERR_TYPE nType, struct bufferevent *bev, short events);
	virtual void OnConnect(struct bufferevent * bev, short events);
	virtual int MakePayloadLength(char* pData, int nLen){return ((pData[2] << 8 | pData[1]) + 1);};
	virtual void SendMsg(char* pMsg);
	virtual void CheckPUCID(CMarkup* pXml);

	virtual void MakeRespXML(const char* pMsgType, CMarkup & xml, int nerrcode);
	void MakeP2PRespXML(const char* pMsgType, CMarkup &xml, int nerrcode, char* sPucId, char* sPuaId, char* sPugId);
private:
	static void cbOnHeartBeetReq(int fd, short events, void* ctx){((CDswWanMsgSession*)ctx)->OnHeartBeetReq(fd, events);};
	void OnHeartBeetReq(int fd, short events);

	void MakeP2PXmlHead(CMarkup* pxml, char* pMsgType);
	virtual bool DealRegisterToP2PServer(void * pMsgReq, const char* pMsgResp);
	virtual bool DealHeartResp(void * pRetMsg, const char* pMsgResp);
	virtual bool DealGetPuaReq(void * pMsgReq, const char* pMsgResp);
	virtual bool DealGetVPortReq(void * pMsgReq, const char* pMsgResp);
	virtual bool DealGetVideoReq(void * pMsgReq, const char* pMsgResp);
	virtual bool DealStopVideoReq(void * pMsgReq, const char* pMsgResp);
	virtual bool DealStartTransVideo(void * pMsgReq, const char* pMsgResp);
	virtual bool DealStopTransVideo(void * pMsgReq, const char* pMsgResp);
private:
	CB_ON_MISSION_NOTIFY m_pNotifyFunc;
	void* m_pParent;
	ST_MISSION_NOTIFY_T m_nNotifyParam;
	char m_sPucID[128];
	char m_sWanIp[64];
	t_svr_param m_nMsgSvr;

	timer_param_t m_nTask_HeartBeet;
};

#endif

